<script>

export default {
  onLaunch: function () {
    var that = this;
    uni.login({
      success: function (res) {
        var code = res.code;

        if (code) {
          //发起网络请求
          uni.getUserInfo({
            withCredentials: true,
            success: function (res_user) {
              console.log(res_user.rawData);
              var rawData = JSON.parse(res_user.rawData);
              uni.setStorageSync("user_avatarUrl", rawData.avatarUrl);
              var jsonData = {
                code: code
              };
              that.globalData.JsonPost('api/login', jsonData, function (data) {
                //存储openid
                uni.setStorageSync("openId", data.msg.openid); //var openid = data.msg.openid;

                that.globalData.JsonPost('api/loginByOpenId', {
                  openid: uni.getStorageSync('openId')
                }, function (data) {
                  console.log('loginByOpenId', data);
                  if (data) {
                    //存储用户信息
					uni.setStorageSync("user", data.data)
					// 以下是之前版本处理方式
                    uni.setStorageSync("userId", data.data.user_id);
                    uni.setStorageSync("userName", data.data.user_name);
                    uni.setStorageSync("userNick", data.data.user_nick);
                    uni.setStorageSync("userDlass", data.data.user_class);
                    uni.setStorageSync("userGrade", data.data.user_grade);
                    uni.setStorageSync("userRoleId", data.data.user_role_id);
                    uni.setStorageSync("userRole", data.data.user_role.role_name);
                  }else{
					    wx.redirectTo({
					      url: '../login/login',
					    })
				  }

                  // uni.switchTab({
                  //   url: '../index/index'
                  // }); 
				  // else {
                  //   wx.redirectTo({
                  //     url: '../login/login',
                  //   })
                  // }
                });
              });
            },
            fail: function () {
              uni.switchTab({
                url: '../index/index'
              }); //获取用户信息失败后，跳转授权页面
              //wx.showModal({
              //  title: '警告',
              //  content: '尚未进行授权，请点击确定跳转到授权页面进行授权。',
              //  complete: function () {
              //    wx.navigateTo({
              //      url: '../tologin/tologin?code=' + code,
              //    })
              //  }
              //})
            }
          });
        } else {
          console.log('获取用户登录态失败！' + res.errMsg);
        }
      },
      fail: function () {
        console.log('登陆失败！');
      }
    });
  },
  globalData: {
    doLogin: function () {
      uni.login({
        success: function (res) {
          var code = res.code;

          if (code) {
            //发起网络请求
            uni.getUserInfo({
              withCredentials: true,
              success: function (res_user) {
                console.log(res_user.rawData);
                var rawData = JSON.parse(res_user.rawData);
                uni.setStorageSync("user_avatarUrl", rawData.avatarUrl);
                var jsonData = {
                  code: code
                };
                that.JsonPost('api/login', jsonData, function (data) {
                  //存储openid
                  uni.setStorageSync("openId", data.msg.openid); //var openid = data.msg.openid;

                  that.JsonPost('api/loginByOpenId', {
                    openid: uni.getStorageSync('openId')
                  }, function (data) {
                    if (data) {
                      //存储用户信息
                      uni.setStorageSync("userId", data.data.user_id);
                      uni.setStorageSync("userName", data.data.user_name);
                      uni.setStorageSync("userNick", data.data.user_nick);
                      uni.setStorageSync("userDlass", data.data.user_class);
                      uni.setStorageSync("userGrade", data.data.user_grade);
                      uni.setStorageSync("userRoleId", data.data.user_role_id);
                      uni.setStorageSync("userRole", data.data.user_role.role_name);
                      uni.switchTab({
                        url: '../index/index'
                      });
                    } else {
                      uni.redirectTo({
                        url: '../login/login'
                      });
                    }
                  });
                });
              },
              fail: function () {
                //获取用户信息失败后，跳转授权页面
                uni.showModal({
                  title: '警告',
                  content: '尚未进行授权，请点击确定跳转到授权页面进行授权。',
                  complete: function () {
                    uni.navigateTo({
                      url: '../tologin/tologin?code=' + code
                    });
                  }
                });
              }
            });
          } else {
            console.log('获取用户登录态失败！' + res.errMsg);
          }
        },
        fail: function () {
          console.log('登陆失败！');
        }
      });
    },
    JsonPost: function (url, data, cb) {
      data.ajax = 1;

      if (uni.getStorageSync("userId") !== '') {
        if (!data.operate_user_id) {
          data.operate_user_id = uni.getStorageSync("userId");
        }
      }
	 //const baseUrl = ' https://actiny.9ok.xin/public/index.php/'
      //const baseUrl = 'http://actiny.wxapp/public/index.php/';
	  const baseUrl = 'https://anruisheng.airuis.xyz/public/index.php/';
      uni.request({
        url: baseUrl + url,
        data: data,
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res.data);

          if (res.data.state == 1) {
            cb(res.data);
          } else if (res.data.state == 2) {
            //cb(false);
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            });
          } else if (res.data.state == 3) {
            //cb(false);
            uni.redirectTo({
              url: '../login/login'
            });
          } else {
            cb(false); //wx.showToast({
            //  title: res.data.msg,
            //  icon: 'none',
            //  duration: 2000
            //})
          }
        }
      });
    },
    isTelphone: function (mobile) {
      var myreg = /^((13|14|15|17|18)+\d{9})$/;

      if (!myreg.test(mobile)) {
        return false;
      } else {
        return true;
      }
    },
    showLoading: function (title) {
      if (!title) {
        title = "数据加载中...请稍后...";
      }

      uni.showLoading({
        title: title
      });
    },
    closeLoading: function () {
      uni.hideLoading();
    },
    formatNumber: function (n) {
      n = n.toString();
      return n[1] ? n : '0' + n;
    },
    formatTime: function (nbr, format) {
      var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
      var returnArr = [];
      var date = new Date(nbr * 1000);
      returnArr.push(date.getFullYear());
      returnArr.push(this.formatNumber(date.getMonth() + 1));
      returnArr.push(this.formatNumber(date.getDate()));
      returnArr.push(this.formatNumber(date.getHours()));
      returnArr.push(this.formatNumber(date.getMinutes()));
      returnArr.push(this.formatNumber(date.getSeconds()));

      for (var i in returnArr) {
        format = format.replace(formateArr[i], returnArr[i]);
      }

      return format;
    },
    timeDiff: function (date1, date2) {
      var s = '';
      var date3 = (date2 - date1) * 1000;
      var days = Math.floor(date3 / (24 * 3600 * 1000));
      var leave1 = date3 % (24 * 3600 * 1000);
      var hours = Math.floor(leave1 / (3600 * 1000));
      var leave2 = leave1 % (3600 * 1000);
      var minutes = Math.floor(leave2 / (60 * 1000));

      if (days == 0) {
        s = hours + "小时" + minutes + "分";
      } else {
        s = days + "天" + hours + "小时" + minutes + "分";
      }

      return s;
    },
    timeContrast: function (date) {
      var d = date * 1000 - new Date().getTime();

      if (d > 0) {
        return true;
      } else {
        return false;
      }
    }
  },
  methods: {}
};
</script>
<style>
/**app.wxss**/
@import "/wxcomponents/vant/dist/common/index.wxss";
page {
  background-color: #efefef;
  min-height: 100%;
  font-family: 微软雅黑;
  line-height: 1.6;
}

/*输入框*/

textarea {
  word-break: break-all;
  word-wrap: break-word;
}

/*清除浮动*/

.clearfix:after {
  content: " ";
  display: block;
  clear: both;
  visibility: hidden;
  line-height: 0;
  height: 0;
  font-size: 0;
}

.fl {
  float: left;
}

.fr {
  float: right;
}

.span {
  display: inline-block;
}

/*对齐*/

.va-m {
  vertical-align: middle;
}

.va-t {
  vertical-align: top;
}

.tl {
  text-align: left;
}

.tr {
  text-align: right;
}

.tc {
  text-align: center;
}

/*内边距*/

.p15 {
  padding: 15px;
}

.pt15 {
  padding-top: 15px;
}

.pr15 {
  padding-right: 15px;
}

.plr15 {
  padding-left: 15px;
  padding-right: 15px;
}

/*外边距*/

.mt5 {
  margin-top: 5px;
}

.mt10 {
  margin-top: 10px;
}

.mt15 {
  margin-top: 15px;
}

.mt20 {
  margin-top: 20px;
}

.ml10 {
  margin-left: 10px;
}

.ml20 {
  margin-left: 20px;
}

.mr5 {
  margin-right: 5px;
}

.mr10 {
  margin-right: 10px;
}

.mr15 {
  margin-right: 15px;
}

.mb10 {
  margin-bottom: 10px;
}

.mb15 {
  margin-bottom: 15px;
}

.mlr5 {
  margin-left: 5px;
  margin-right: 5px;
}

/*文字省略*/

.mui-ellipsis {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mui-ellipsis-2 {
  display: -webkit-box;
  overflow: hidden;
  white-space: normal !important;
  text-overflow: ellipsis;
  word-wrap: break-word;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/*弹性盒子*/

.layout-box, .layout-cell, .layout-center, .layout-ctlr, .layout-end,
.layout-col {
  display: box;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
}

.layout-center, .layout-ctlr, .layout-cell {
  align-items: center;
  -webkit-align-items: center;
  box-align: center;
  -webkit-box-align: center;
}

.layout-ctlr {
  -webkit-justify-content: space-between;
  justify-content: space-between;
}

.layout-end {
  -webkit-align-items: flex-end;
  align-items: flex-end;
}

.layout-cell {
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}

.layout-col {
  flex-direction: column;
}

.flex-item {
  -webkit-box-flex: auto;
  -webkit-flex: auto;
  flex: auto;
}

.flex-item1 {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  width: 0%;
  min-width: 0;
}

.flex-grow1 {
  flex-grow: 1;
}

.flex-first {
  -webkit-order: -1;
  order: -1;
}

.flex-end {
  -webkit-justify-content: flex-end;
  justify-content: flex-end;
}

/*列表箭头*/

.t-arrow, .r-arrow, .b-arrow {
  position: relative;
}

.r-arrow:before, .t-arrow:before, .b-arrow:before {
  content: " ";
  display: inline-block;
  height: 18rpx;
  width: 18rpx;
  border-width: 2rpx 2rpx 0 0;
  border-color: #888;
  border-style: solid;
  position: absolute;
  top: 50%;
  right: 15px;
  z-index: 9;
}

.r-arrow:before {
  transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
  margin-top: -8rpx;
}

.t-arrow:before {
  transform: matrix(0.71, -0.71, 0.71, 0.71, 0, 0);
  margin-top: -4rpx;
}

.b-arrow:before {
  transform: matrix(-0.71, 0.71, -0.71, -0.71, 0, 0);
  margin-top: -12rpx;
}

/*横向滚动  */

.scroll-view_H {
  white-space: nowrap;
}

.scroll-view-item_H {
  display: inline-block;
}

/*提交按钮*/

button::after {
  border: 0;
}

.btn-box {
  padding: 10px 15px 20px 15px;
}

.btn-box .tip {
  color: #969696;
  font-size: 12px;
  line-height: 20px;
  padding: 10px 2px 0 2px;
}

.send-btn::after {
  border: 0;
}

.send-btn {
  display: block;
  width: 100%;
  color: #fff;
  font-size: 15px;
  line-height: 38px;
  background-color: #298ceb;
  padding: 0;
  border: 1px solid #298ceb;
  border-radius: 5px;
  margin: 0;
}

.send-btn[disabled], .send-btn[disabled]:not([type]) {
  color: #fff;
  background-color: #68adf0;
  border: 1px solid #68adf0;
}

/* 下拉提示 */

.loadmore {
  width: 100%;
  color: #969696;
  font-size: 14px;
  text-align: center;
  padding: 10px 0;
}

/* 暂无数据 */

.on-data {
  padding: 35% 0;
  text-align: center;
}

.on-data .iconfont {
  color: #969696;
  font-size: 100px;
  line-height: 100px;
}

.on-data .no-text {
  color: #000;
  font-size: 18px;
  margin-top: 10px;
}

@font-face {
    font-family: 'iconfont';
    src: url(data:application/font-woff2;charset=utf-8;base64,d09GMgABAAAAAAX4AA0AAAAAC4gAAAWkAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP0ZGVE0cGh4GVgCCWhEICoo8iB8LEAABNgIkAxYEIAWFCAdLG3MJUZROUofsR2Jso2YrBJVKWWhzmCAWiynC3/wIr/pX1R0s7AxO4mCl3B5gfRg8T93o/d0tTCCwZgJJAw6iyM/OTvSALrPkBPbYfvXMncOuIyf+VbKFIvbkm4YklqA+6jB8Uwll5epeX9OqUGbTNCJBvLSupeKb0EuoFw5GIBMM1WqtAwWogcT4i36kD/YH3JmIF56wEgAC4Pm2NB0A3iQecXL3JoA3IBTACFERCWAANdAbA/CL7wFYCHye/rBGB5hSwQ3terVyounj85kpJv1vHQwBLqAok2BM0T5iTwNh35PqAjzpGD8+n4V81vEz8/8O2M9G/BbxfcTpiCUIwUMjPPVQAcDAXw8BxKh3MJZmii8gGugGngBIScsFUDA5zrRwem2tUu0VE6VqZcgILg3XOIexkkGw8pk0TyS/fdfmMqIAbWQfS0qO8kWSMFTMhhBE1UcTAVBLZnUFCcAZyF/n0QiUGMwyEVR6dZIt5AUiKntB4h1ZLKRL4KjAixdWCBWYfaoeCnH/vnkMxhnhwdEeb1YBSU4SL0hWiHVxHJx2IgSHym+6vygOI87nIxjBmM1nNiaPmabLrQqJRmlHOHJ6kQ4zMRovt9JOF3I681GDD0fywahCyKtUEBwetF5K6X3mrzCOgC9GhUFqlFLZ+zkq4c2lpSQlqruZ8/z+Am+ivjcfGaZWhSC806Tp6J0H9qF/7B4dLN35MtJ38euC8v3v4/2Xvh0q+8D6Sv0unisVBFBmFvk5gOx3FzqdrNVK2u3Ud7emoIJ/7M53uzkrC0IRphORU9mbFuObbVH+353Xe61z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1udJaApQ6+6y5ietvz/UiG9L/s5Hnmj05l+ujy9PpqhiMZspWjk83TRKc3s+nznSjqYF1KBGJVpvCiFHoXXV/9D00iwccAAHjafZA9TgMxEIWf8wckEkIgqF1RANr8lCkTKfQIpaNINt6QaNdeeZ1IOQEtFQeg5RgcgBsg0XIKXpZJkyJr7ejzm5nnsQGc4xsK/98l7oQVjvEoXMERMuEq9RfhGvlduI4WPoUb1H+Em7hVA+EWLtQbHVTthLub0m3LCmcYCFdwiifhKvWVcI38KlzHFT6EG9S/hJsY41e4hWtlqQzhYTBBYJxBY4oN4wIxHCySMgbWoTn0ZhLMTE83ehE7mzgbKO9XYpcDHmg554Ap7T23Zr5KJ/5gy4HUmG4eBUu2KY0uInQoG18snNXdqHOw/Z7ttrTYv2uBNcfsUQ1s1Pw92zPSSGwMr5CSNfIyt6QSU49oa6zxu2cp1vNeCIlOvMv0iMeaNHU6925p4sDi5/KMHH20uZI996gcPmNZCHm/3U7EIIpdhj+T2HEZAAAAeNpjYGKAAC4wyciADtjBokyMTIzMjCyMrOx5+bopiSWJbMUZ+aVZmWzFqYlFyRksuZm5iQCGsAmRAAAAAAAAAf//AAJ42mNgZGBg4AFiMSBmYmAEQjYgZgHzGAAD4AA1eNpjYGBgZACCq0vUOUD0LaVNKTAaADwHBc4AAA==) format('woff');
    font-weight: normal;
    font-style: normal;
}

.iconfont {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


.icon-search:before {
  content: "\e64c";
}

.icon-mima:before {
  content: "\e674";
}

.icon-shouji:before {
  content: "\e615";
}

.icon-no-data:before {
  content: "\e60d";
}

</style>